package com.qidianit.mes.pro.controller;

import com.github.pagehelper.PageInfo;
import com.qidianit.mes.pojo.Result;
import com.qidianit.mes.pojo.qc.CommonDefect;
import com.qidianit.mes.pro.service.CommonDefectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 常见缺陷控制器
 */
@RestController
@RequestMapping("/commonDefect")
public class CommonDefectController {

    @Autowired
    private CommonDefectService commonDefectService;

    /**
     * 多条件分页查询
     * 注意返回类型应为 Result<PageInfo<CommonDefect>>
     */
    @GetMapping("/list")
    public Result<PageInfo<CommonDefect>> selectList(
            CommonDefect commonDefect,
            @RequestParam(defaultValue = "1") int pageNum,
            @RequestParam(defaultValue = "10") int size) {
        // 这里的返回类型与Service层保持一致


        System.out.println();
        return commonDefectService.selectList(commonDefect, pageNum, size);
    }

    /**
     * 保存常见缺陷
     */
    @PostMapping("/add")
    public Result save(@RequestBody CommonDefect commonDefect) {
        return commonDefectService.save(commonDefect);
    }

    /**
     * 根据ID更新
     */
    @PostMapping("/update")
    public Result updateById(@RequestBody CommonDefect commonDefect) {
        return commonDefectService.updateById(commonDefect);
    }

    /**
     * 根据ID删除
     */
    @DeleteMapping ("/delete/{id}")
    public Result deleteById(@PathVariable Long id) {
        return commonDefectService.deleteById(id);
    }

    /**
     * 批量删除
     */
    @DeleteMapping ("/batchDelete")
    public Result batchDelete(@RequestBody Long[] ids) {
        return commonDefectService.batchDelete(ids);
    }

    @GetMapping("/get/{id}")
    public Result selectById(@PathVariable Long  id){
        return commonDefectService.selectById(id);
    }
}
